import sqlite3
import json
from flask import jsonify
from flask import render_template, request
import app

@app.app.route('/')
@app.app.route('/home/')
def index():
    return render_template('home.html')

@app.app.route('/courses/')
def courses():
    return render_template('courses.html')

@app.app.route('/requirements/')
def requirements():
    return render_template('requirements.html')

@app.app.route('/courses/get_courses/')
def get_courses():
    #print request.args
    pillar = request.args['pillar']
    req_type = request.args['req_type']
    req_type = 1 if req_type == 'distribution' else 2
    db = app.connect_db()
    #print req_type
    c = db.execute('select abbr, title, description, offered from klasses where pillar_type = "%s" and req_type = "%s"' % (pillar, req_type))
    out = c.fetchall()
    db.close()
    return jsonify({'data': out,
                    'type': 'distribution' if req_type is 1 else 'concentration',
                    'msg_id': request.args['msg_id']})
